package com.liangtian.mdm.material.service.impl;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.liangtian.mdm.material.dao.WlwlFieldDao;
import com.liangtian.mdm.material.model.WlwlField;
import com.liangtian.mdm.material.model.WlwlFieldSelectValue;
import com.liangtian.mdm.material.service.WlwlFieldService;

@Service
public class WlwlFieldServiceImpl implements WlwlFieldService {

    //注入dao接口
    @Autowired
    private WlwlFieldDao wlwlFieldDao;

    @SuppressWarnings({"unchecked", "rawtypes"})
    @Override
    public PageInfo queryWlwlField(Map<String, Object> cond) {
        PageInfo pageInfo = null;
        try {
            /*
             * 参数
             * @params参数详情 pageNum 总页数
             * @params参数详情 length 每页显示条数
             * @params参数详情 start 起始条数
             * @params参数详情 draw 请求次数
             * @return 分页条件下的
             */
            Object pNo = cond.get("pageNum");
            int pageNum, pageSize;
            // export
            if (pNo != null && !"NaN".equals(pNo)) {
                pageNum = Integer.parseInt(pNo.toString());// 页码
            } else {
                pageNum = 1;
            }
            // pageSize=0时不分页
            pageSize = Integer.parseInt(cond.get("limit").toString());// 模型定义页面要显示数据条数
            // 例如
            // 10,20,50,100
            PageHelper.startPage(pageNum, pageSize);// 开始分页标志（当前页，显示条数）

            List<WlwlField> list = wlwlFieldDao.queryWlwlField(cond);
            pageInfo = new PageInfo(list);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return pageInfo;
    }

    @Override
    public int updateWlwlField(Map<String, Object> cond) {
        return wlwlFieldDao.updateWlwlField(cond);
    }

    @Override
    public WlwlField queryWlwlFieldById(String field) {
        return wlwlFieldDao.queryWlwlFieldById(field);
    }

    @Override
    public List<WlwlField> queryWlwlFieldByCond(Map<String, Object> cond) {
        return wlwlFieldDao.queryWlwlField(cond);
    }

    @Override
    public List<WlwlFieldSelectValue> queryWlwlFieldSelectValueListByCond(
            Map<String, Object> cond) {
        return wlwlFieldDao.queryWlwlFieldSelectValueListByCond(cond);
    }

}
